<template>
  <div>
    <van-address-list
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect"
    />

    <van-empty v-if="list.length === 0" description="暂无数据"></van-empty>
  </div>
</template>

<script>
import { reqAddressList } from "../../http/api";
export default {
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    reqAddressList({
      uid: JSON.parse(localStorage.getItem("isLogin")).uid,
    }).then((res) => {
      if (res.data.code === 200) {
        var list = res.data.list ? res.data.list : [];
        this.list = list.map((item) => {
          return {
            id: item.id,
            name: item.username,
            tel: item.userphone,
            address: item.location+item.useraddress,
            isDefault: item.status==1,
          };
        });
      }
    });
  },
  methods: {
    onAdd() {
      this.$router.push("/newadd");
    },
    onEdit(item, index) {
       this.$router.push("/newadd?id="+item.id);
    },
    onSelect(item,index){
      this.$router.replace("/order?addressId="+item.id)
    }
  },
};
</script>

<style lang="less">
@import "../../less/index.less";
</style>